package cn.itcast.service.impl;

import cn.itcast.dao.OrderDao;
import cn.itcast.dao.ReportMemberDao;
import cn.itcast.service.OrderService;
import cn.itcast.service.ReportService;
import cn.itcast.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(version = "1.0.0")
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMemberDao reportMemberDao;

    @Autowired
    private OrderService orderService;

    @Override
    public List<Integer> findReportMember(List<String> months) {
        List<Integer> memberCount=new ArrayList<>();
        //对months进行处理
        for (String month : months) {
            String date = month + ".31";
           Integer count= this.reportMemberDao.findMemberByMonths(date);
           memberCount.add(count);
        }
        return memberCount;
    }
/*
    reportData: {
        reportDate: null,//当前日期
                todayNewMember: 0,//本日新增会员数
                totalMember: 0,//总会员数
                thisWeekNewMember: 0,//本周新增会员数
                thisMonthNewMember: 0,//本月新增会员数
                todayOrderNumber: 0,//今日预约数
                todayVisitsNumber: 0,//今日到诊数
                thisWeekOrderNumber: 0,//本周预约数
                thisWeekVisitsNumber: 0,//本周到诊数
                thisMonthOrderNumber: 0,//本月预约数
                thisMonthVisitsNumber: 0,//本月到诊数
                hotSetmeal: [
        {name: '阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐', setmeal_count: 200, proportion: 0.222},
        {name: '阳光爸妈升级肿瘤12项筛查体检套餐', setmeal_count: 200, proportion: 0.222}
                ]
    }*/
    @Override
    public Map<String, Object> findBusiness() throws Exception {
        Map<String, Object> map =new HashMap<>();
        //当前日期
        String today=DateUtils.parseDate2String(DateUtils.getToday());
        map.put("reportDate",today);
        //获取本周一日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月一的日期
        String firstDay4ThisMonth= DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //本日新增会员数
        Integer todayNewMember=this.reportMemberDao.findMemberByDate(today);
        //总会员数
        Integer totalMember=this.reportMemberDao.findMemberTotal();
        //本周新增会员数eek
        Integer thisWeekNewMember=this.reportMemberDao.findMemberCountWeekAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer thisMonthNewMember=this.reportMemberDao.findMemberCountMonthAfterDate(firstDay4ThisMonth);
        //今日预约数
        Integer todayOrderNumber=this.orderService.findOrderCountByDate(today);
        //今日到诊数
        Integer todayVisitsNumber = this.orderService.findVisitsCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber=this.orderService.findOrderCountWeekAfterDate(thisWeekMonday);
        //本周到诊数
        Integer thisWeekVisitsNumber=this.orderService.findVisitsCountWeekAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber=this.orderService.findOrderCountMonthAfterDate(firstDay4ThisMonth);
        //本月到诊数
        Integer thisMonthVisitsNumber=this.orderService.findVisitsCountMonthAfterDate(firstDay4ThisMonth);


        //热门套餐。预约数据多的 order.setmeal
        List<Map> hotSetmeal=this.orderService.findhotSetmeal();
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);

        return map;
    }

    @Override
    public List<Double> findIncome(List<String> months) {
        List<Double> memberCount=new ArrayList<>();
        //对months进行处理
        for (String month : months) {
            String date = month + ".31";
            Double count= this.reportMemberDao.findIncomeByMonths(date);
            memberCount.add(count);
        }
        return memberCount;
    }

    @Override
    public List<Integer> findOrder(List<String> months){
        List<Integer> orderCount=new ArrayList<>();
        //对months进行处理
        for (String month : months) {
            String date = month + ".31";
            Integer count= this.reportMemberDao.findOrderByMonths(date);
            orderCount.add(count);
        }
        return orderCount;
    }
}
